﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors.DXErrorProvider;
using DevExpress.XtraLayout;
using DevExpress.XtraEditors;
using DevExpress.Utils;
using DevExpress.XtraBars;
using DevExpress.XtraSplashScreen;
using DevExpress.XtraWaitForm;
using System.Reflection;
using System.Diagnostics;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraTreeList.Columns;
using HouseSecretary.Common;
using DevExpress.XtraBars.Docking.Paint;
using DevExpress.XtraBars.Styles;
using DevExpress.XtraBars.Docking;
using DevExpress.XtraGrid.Views.Grid;
using Newtonsoft.Json.Linq;

namespace HouseSecretary.Base
{

    public partial class BaseForm : DevExpress.XtraEditors.XtraForm
    {
        private bool IsWriteLog = true;
        /// <summary>
        /// Form的基类
        /// 记录日志
        /// </summary>
        public BaseForm()
        {
            InitializeComponent();
            IsWriteLog = false;

            this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            this.UpdateStyles();

        }
        /// <summary>
        /// 设置是否记录日志
        /// </summary>
        /// <param name="isWriteLog"></param>
        public BaseForm(bool isWriteLog)
        {
            InitializeComponent();
            IsWriteLog = isWriteLog;
            this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            this.UpdateStyles();

        }


        /// <summary>
        /// 重写keyPress 回车键代替TAB键
        /// 设置窗体的KeyPreview属性为True
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                Control ctl = this.ActiveControl;
                if (ctl is LayoutControl)
                {
                    LayoutControl layControl = ctl as LayoutControl;
                    ctl = layControl.ActiveControl;
                }
                if (ctl.GetType().Name == typeof(TextBoxMaskBox).Name)
                {
                    ctl = ctl.Parent;
                }
                if (ctl != null)
                {
                    if (ctl.GetType().Name != typeof(MemoEdit).Name)
                    {
                        SendKeys.Send("{TAB}");
                    }
                }
            }

            base.OnKeyPress(e);
        }

        protected override void OnLoad(EventArgs e)
        {

            if (!this.DesignMode)
            {

#if DEBUG
                this.Text += "-" + this.Name;
#else

#endif
                this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.BaseForm_FormClosed);
                //记录开始时间
                if (IsWriteLog)
                {
                }
                this.KeyPreview = true;

            }
            base.OnLoad(e);

        }

        void gdview_RowStyle(object sender, RowStyleEventArgs e)
        {
            if (e.RowHandle % 2 == 0)
            {
                e.Appearance.BackColor = Color.FromArgb(240, 248, 255);
            }
        }

        private DateTime? StartDatetime = null;
        private DateTime? EndDatetime = null;
        /// <summary>
        /// 增加日志
        /// <creator>wangl</creator>
        /// <date>2012-01-05</date> 
        /// </summary>
        private void AddFrmLogInfo()
        {
        }
        /// <summary>
        /// 用户增加日志
        /// <creator>wangl</creator>
        /// <date>2012-04-01</date>
        /// </summary>
        protected void AddFrmLogInfoByUser(string context, DateTime? startDateTime)
        {
           
        }
        private void BaseForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            GC.Collect();
        }
        /// <summary>
        /// 返回菜单图标的集合
        /// <creator>wangl</creator>
        /// <date>2012-01-05</date> 
        /// </summary>
        /// <returns></returns>
        protected ImageCollection GetMenuImageCollection()
        {
            return imgCollectMenu;
        }
        /// <summary>
        /// 返回界面图标的集合
        /// <creator>wangl</creator>
        /// <date>2012-01-10</date> 
        /// </summary>
        /// <returns></returns>
        protected ImageCollection GetFormImageCollection()
        {
            return imgCollectForm;
        }
        /// <summary>
        /// 根据名字获取imageList中的imageIndex
        /// <creator>wangl</creator>
        /// <date>2012-01-05</date> 
        /// </summary>
        /// <param name="imgName"></param>
        /// <returns></returns>
        protected int GetImageIndex(string imgName, ImageCollection imgCollect)
        {
            int index = -1;
            Image img = imgCollect.Images[imgName];
            for (int i = 0; i < imgCollect.Images.Count; i++)
            {
                if (imgCollect.Images[i] == img)
                {
                    index = i;
                    break;
                }

            }
            return index;
        }
        
        /// <summary>
        /// 根据菜单名称返回登录用户是否具有此菜单的权限
        /// <creator>zhangy</creator>
        /// <date>2012-02-13</date> 
        /// </summary>
        /// <param name="menuName"></param>
        /// <returns></returns>
        protected bool ExistsMenu(string menuName, Bar barMenu)
        {
            int i = 0;
            bool bl = false;
            foreach (LinkPersistInfo liParent in barMenu.LinksPersistInfo)
            {
                if (menuName == liParent.Item.Name)
                {
                    i++;
                    bl = liParent.Visible;
                    break;
                }
                else
                {
                    foreach (LinkPersistInfo liChild in ((BarSubItem)liParent.Item).LinksPersistInfo)
                    {
                        if (menuName == liChild.Item.Name)
                        {
                            i++;
                            bl = liParent.Visible;
                            break;
                        }
                    }
                }
            }
            if (i == 0)
            {
                return false;
            }
            else
            {
                return bl;
            }
        }
       
       



        #region 相关界面方法(主要是控件和数据库相关)
        private SplashScreenManager sFlashScreen = null;
        /// <summary>
        /// 打开等待窗口(注意：调用该方法后,必须调用CloseWaitForm()方法)
        /// <creator>wangl</creator>
        /// <date>2012-01-31</date> 
        /// </summary>
        /// <param name="hwnd">当前窗口指针</param>
        protected void OpenWaitForm(IntPtr hwnd, string msg = "")
        {
            this.Cursor = Cursors.WaitCursor;
            sFlashScreen = new SplashScreenManager(null, typeof(DemoWaitForm), false, true);
            //Common.ImportDllApiUtil.EnableWindow(hwnd, false);
            sFlashScreen.ShowWaitForm();
            if (msg == "")
            {
                sFlashScreen.SetWaitFormDescription("数据加载中...");
            }
            else
            {
                sFlashScreen.SetWaitFormDescription(msg);
            }
            sFlashScreen.SetWaitFormCaption("");



        }

        /// <summary>
        /// 关闭等待窗口
        /// </summary>
        /// <param name="hwnd"></param>
        protected void CloseWaitForm()
        {
            try
            {
                if (sFlashScreen != null)
                {
                    sFlashScreen.CloseWaitForm();
                }
            }
            catch
            {

            }
            finally
            {
                this.Cursor = Cursors.Default;
               // Common.ImportDllApiUtil.EnableWindow(this.Handle, true);
                
            }

        }

        ///// <summary>
        ///// 判断手机号码是否符合手机号码段标准
        ///// <creator>rend</creator>
        ///// <date>2012-02-01</date> 
        ///// </summary>
        ///// <param name="mobile"></param>
        ///// <returns></returns>
        //protected bool MobileNoRange(string mobile)
        //{
        //    bool bl = false;
        //    if (mobile.Length == 11 || mobile.Length == 12)
        //    {
        //        BLL.ClientEdit ClientEditBll = new BLL.ClientEdit();
        //        List<Model.MobileNoRange> mobileList = ClientEditBll.GetMobileNoRangeListAll();
        //        if (mobileList.Count == 0)
        //        {
        //            bl = true;
        //        }
        //        else
        //        {
        //            mobileList.ForEach(c =>
        //            {
        //                if (mobile.IndexOf(c.FMobileBeginNo) == 0)
        //                {
        //                    bl = true;
        //                    return;
        //                }
        //            });
        //        }
        //    }
        //    return bl;
        //}


        #endregion


        #region 程序集特性访问器

        public string AssemblyTitle
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        public string AssemblyVersion
        {
            get
            {
                //return Assembly.GetExecutingAssembly().GetName().Version.Major + "." + Assembly.GetExecutingAssembly().GetName().Version.Minor;
                FileVersionInfo myFileVersion = FileVersionInfo.GetVersionInfo(System.Windows.Forms.Application.ExecutablePath);
                string[] versonStringList = myFileVersion.ProductVersion.Split(new char[1] { '.' });


                return versonStringList[0] + "." + versonStringList[1];
            }
        }

        public string AssemblyDescription
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }

        public string AssemblyProduct
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }

        public string AssemblyCopyright
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        public string AssemblyCompany
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        #endregion

    }
    /// <summary>
    /// grid右键菜单类
    /// <creator>wangl</creator>
    /// <date>2012-02-22</date> 
    /// </summary>
    class EASGridMenuInfo
    {
        public EASGridMenuInfo(GridColumn column, DevExpress.XtraGrid.Columns.FixedStyle style, bool check)
        {
            this.Column = column;
            this.Style = style;
            this.Checked = check;
        }
        public DevExpress.XtraGrid.Columns.FixedStyle Style;
        public GridColumn Column;
        public bool Checked;
    }
    /// <summary>
    /// grid右键菜单信息类
    /// <creator>wangl</creator>
    /// <date>2012-02-22</date> 
    class EASTreeListMenuInfo
    {
        public EASTreeListMenuInfo(TreeListColumn column, DevExpress.XtraTreeList.Columns.FixedStyle style, bool check)
        {
            this.Column = column;
            this.Style = style;
            this.Checked = check;
        }
        public DevExpress.XtraTreeList.Columns.FixedStyle Style;
        public TreeListColumn Column;
        public bool Checked;
    }

    #region 相关验证规则
    /// <summary>
    /// 不能为空
    /// <creator>wangl</creator>
    /// <date>2012-02-22</date> 
    /// </summary>
    public class NotBlankValidationRule : ValidationRule
    {
        public override bool Validate(Control control, object value)
        {
            bool res = false;
            if (value != DBNull.Value)
            {
                if (value != null)
                {
                    string str = value.ToString();
                    str = str.Trim();

                    if (str != "")
                    {
                        res = true;
                    }
                }
            }
            return res;
        }
    }
    /// <summary>
    /// 大于0 (错误信息由各个调用程序自行定义)
    /// <creator>wangl</creator>
    /// <date>2012-03-21</date> 
    /// </summary>
    public class MoreThanZeroValidationRule : ValidationRule
    {
        public override bool Validate(Control control, object value)
        {
            bool res = false;
            if (value != DBNull.Value)
            {
                if (value != null)
                {
                    decimal d = 0;
                    if (decimal.TryParse(value.ToString(), out d))
                    {
                        if (d > 0)
                        {
                            res = true;
                        }
                        else
                        {
                            if (this.ErrorText == "")
                            {
                                this.ErrorText = "必须大于0!";
                            }
                        }
                    }
                }
            }
            return res;
        }
    }
    /// <summary>
    /// 两个数字之间,包含边界
    /// decimal? d1,decimal? d2
    /// <creator>wangl</creator>
    /// <date>2012-03-22</date>
    /// </summary>
    public class BetweenNumValidationRule : ValidationRule
    {
        private decimal? minDecimal;
        private decimal? maxDecimal;
        public BetweenNumValidationRule(decimal? d1, decimal? d2)
        {
            minDecimal = d1;
            maxDecimal = d2;
        }
        public override bool Validate(Control control, object value)
        {
            bool res = false;
            if (value != DBNull.Value)
            {
                if (value != null)
                {
                    decimal d = 0;
                    if (decimal.TryParse(value.ToString(), out d))
                    {
                        if (minDecimal.HasValue && maxDecimal.HasValue)
                        {
                            if (d >= minDecimal.Value && d <= maxDecimal.Value)
                            {
                                res = true;
                            }
                        }
                        else
                        {
                            if (minDecimal.HasValue)
                            {
                                if (d >= minDecimal.Value)
                                {
                                    res = true;
                                }
                            }
                            else
                            {
                                if (maxDecimal.HasValue)
                                {
                                    if (d <= maxDecimal.Value)
                                    {
                                        res = true;
                                    }
                                }
                            }
                        }
                        if (!res)
                        {
                            if (this.ErrorText == "")
                            {
                                this.ErrorText = "必须符合区间范围!";
                            }
                        }


                    }
                }
            }
            return res;
        }
    }
    /// <summary>
    /// 编码验证
    /// <creator>wangl</creator>
    /// <date>2012-02-22</date> 
    /// </summary>
    public class CodeValidationRule : ValidationRule
    {
        public override bool Validate(Control control, object value)
        {
            bool res = false;
            if (value != DBNull.Value)
            {
                if (value != null)
                {
                    string str = (string)value;
                    str = str.Trim();
                    res = Common.GlobalUtil.CheckCodeValidate(str);
                }
            }
            return res;
        }
    }
    /// <summary>
    /// 绑定MODEL下拉框验证
    /// <creator>zhongyl</creator>
    /// <date>2012-02-23</date>
    /// </summary>
    public class notEmptyCboValidationRule : ValidationRule
    {
        public override bool Validate(Control control, object value)
        {
            bool res = false;
            if (value != DBNull.Value)
            {
                if (value != null)
                {
                    res = true;
                }
            }
            return res;
        }
    }

    ///// <summary>
    ///// 手机号码段验证  可空
    ///// <creator>rend</creator>
    ///// <date>2012-02-25</date> 
    ///// </summary>
    //public class MobilValidationRule : ValidationRule
    //{
    //    public override bool Validate(Control control, object value)
    //    {
    //        bool res = true;
    //        if (value != DBNull.Value)
    //        {
    //            if (null != value)
    //            {
    //                string str = ((string)value).Trim();
    //                if (str != string.Empty)
    //                {
    //                    res = GlobalUtil.CheckMobilValidate(str);
    //                    if (res == true)
    //                    {
    //                        res = UtilDate.MobileNoRange(str);
    //                        this.ErrorText = "手机号码在号码段中不存在!";
    //                    }
    //                    else
    //                    {
    //                        this.ErrorText = "格式不正确,请输入11位或0开始的12位数字!";

    //                    }
    //                }
    //            }
    //        }

    //        return res;
    //    }
    //}


    ///// <summary>
    ///// 手机号码段验证  不可空
    ///// <creator>rend</creator>
    ///// <date>2012-02-25</date> 
    ///// </summary>
    //public class MobilNoEmptyValidationRule : ValidationRule
    //{
    //    public override bool Validate(Control control, object value)
    //    {
    //        bool res = false;
    //        this.ErrorText = "值不能为空!";
    //        if (value != DBNull.Value)
    //        {
    //            if (null != value)
    //            {
    //                string str = ((string)value).Trim();
    //                if (str != string.Empty)
    //                {
    //                    res = GlobalUtil.CheckMobilValidate(str);
    //                    if (res == true)
    //                    {
    //                        res = UtilDate.MobileNoRange(str);
    //                        this.ErrorText = "手机号码在号码段中不存在!";
    //                    }
    //                    else
    //                    {
    //                        this.ErrorText = "格式不正确,请输入11位或0开始的12位数字!";

    //                    }
    //                }
    //            }
    //        }

    //        return res;
    //    }
    //}
    /// <summary>
    /// 验证手机号码11位或0开始的12位数字
    /// <creator>wangl</creator>
    /// <date>2012-09-11</date> 
    /// </summary>
    public class MobleNumberValidationRule : ValidationRule
    {
        /// <summary>
        /// 重载验证函数
        /// </summary>
        /// <param name="control"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool Validate(Control control, object value)
        {
            bool res = false;
            this.ErrorText = "值不能为空!";
            if (value != DBNull.Value)
            {
                if (value != null)
                {
                    string str = ((string)value).Trim();
                    if (str != "")
                    {
                        res = GlobalUtil.CheckMobilValidate(str);
                        if (!res)
                        {
                            this.ErrorText = "格式不正确,请输入11位或0开始的12位数字!";
                        }
                    }
                }
            }
            return res;
        }
    }



    ///// <summary>
    /////  电话号码(可输入分机号)/手机号码  可空
    ///// <creator>rend</creator>
    ///// <date>2012-02-25</date> 
    ///// </summary>
    //public class TelExtensionAndMobilValidationRule : ValidationRule
    //{
    //    public override bool Validate(Control control, object value)
    //    {
    //        bool res = true;
    //        if (value != DBNull.Value)
    //        {
    //            if (null != value)
    //            {
    //                string str = ((string)value).Trim();
    //                if (str != string.Empty)
    //                {
    //                    res = GlobalUtil.CheckTelExtensionAndMobilValidate(str);
    //                    if (res == true)
    //                    {
    //                        if ((str.Length == 11 || str.Length == 12) && str.IndexOf('-') == -1 && str.IndexOf('(') == -1 && str.IndexOf(')') == -1 && str.IndexOf('*') == -1)
    //                        {
    //                            res = UtilDate.MobileNoRange(str);
    //                            this.ErrorText = "号码在号码段中不存在!";
    //                        }
    //                    }
    //                    else
    //                    {
    //                        this.ErrorText = "格式不正确";

    //                    }
    //                }
    //            }
    //        }

    //        return res;
    //    }
    //}


    ///// <summary>
    /////  电话号码(可输入分机号)/手机号码  不可空
    ///// <creator>rend</creator>
    ///// <date>2012-02-25</date> 
    ///// </summary>
    //public class TelExtensionAndMobilNoEmptyValidationRule : ValidationRule
    //{
    //    public override bool Validate(Control control, object value)
    //    {
    //        bool res = false;
    //        this.ErrorText = "值不能为空!";
    //        if (value != DBNull.Value)
    //        {
    //            if (null != value)
    //            {
    //                string str = ((string)value).Trim();
    //                if (str != string.Empty)
    //                {
    //                    res = GlobalUtil.CheckTelExtensionAndMobilValidate(str);
    //                    if (res == true)
    //                    {
    //                        if ((str.Length == 11 || str.Length == 12) && str.IndexOf('-') == -1 && str.IndexOf('(') == -1 && str.IndexOf(')') == -1 && str.IndexOf('*') == -1)
    //                        {
    //                            res = UtilDate.MobileNoRange(str);
    //                            this.ErrorText = "号码在号码段中不存在!";
    //                        }
    //                    }
    //                    else
    //                    {
    //                        this.ErrorText = "格式不正确";

    //                    }
    //                }
    //            }
    //        }

    //        return res;
    //    }
    //}


    ///// <summary>
    /////  电话号码/手机号码  可空
    ///// <creator>rend</creator>
    ///// <date>2012-02-25</date> 
    ///// </summary>
    //public class TelAndMobilValidationRule : ValidationRule
    //{
    //    public override bool Validate(Control control, object value)
    //    {
    //        bool res = true;
    //        if (value != DBNull.Value)
    //        {
    //            if (null != value)
    //            {
    //                string str = ((string)value).Trim();
    //                if (str != string.Empty)
    //                {
    //                    res = GlobalUtil.CheckTelAndMobilValidate(str);
    //                    if (res == true)
    //                    {
    //                        if ((str.Length == 11 || str.Length == 12) && str.IndexOf('-') == -1 && str.IndexOf('(') == -1 && str.IndexOf(')') == -1 && str.IndexOf('*') == -1)
    //                        {
    //                            res = UtilDate.MobileNoRange(str);
    //                            this.ErrorText = "号码在号码段中不存在!";
    //                        }
    //                    }
    //                    else
    //                    {
    //                        this.ErrorText = "格式不正确";
    //                    }
    //                }
    //            }
    //        }

    //        return res;
    //    }
    //}


    ///// <summary>
    /////  电话号码/手机号码  不可空
    ///// <creator>rend</creator>
    ///// <date>2012-02-25</date> 
    ///// </summary>
    //public class TelAndMobilNoEmptyValidationRule : ValidationRule
    //{
    //    public override bool Validate(Control control, object value)
    //    {
    //        bool res = false;
    //        this.ErrorText = "值不能为空!";
    //        if (value != DBNull.Value)
    //        {
    //            if (null != value)
    //            {
    //                string str = ((string)value).Trim();
    //                if (str != string.Empty)
    //                {
    //                    res = GlobalUtil.CheckTelAndMobilValidate(str);
    //                    if (res == true)
    //                    {
    //                        if ((str.Length == 11 || str.Length == 12) && str.IndexOf('-') == -1 && str.IndexOf('(') == -1 && str.IndexOf(')') == -1 && str.IndexOf('*') == -1)
    //                        {
    //                            res = UtilDate.MobileNoRange(str);
    //                            this.ErrorText = "号码在号码段中不存在!";
    //                        }
    //                    }
    //                    else
    //                    {
    //                        this.ErrorText = "格式不正确";
    //                    }
    //                }
    //            }
    //        }

    //        return res;
    //    }
    //}

    

    /// <summary>
    /// 判断项目类型编码, 不能为空和必须唯一
    /// <creator>wangl</creator>
    /// <date>2012-02-22</date> 
    /// </summary>
    public class NotPrjClassCdValueValidationRule : ValidationRule
    {
        public string prjClassCd = "";
        public override bool Validate(Control control, object value)
        {
            bool res = false;
            this.ErrorText = "项目类型编码不能为空";
            if (value != DBNull.Value)
            {
                if (value != null)
                {
                    string str = value.ToString().Trim();

                    if (str != "")
                    {
                        //BLL.PrjClass prjClassBLL = new BLL.PrjClass();
                        //if (prjClassBLL.Exists(prjClassCd + str))//判断该编号是否已经存在
                        //{
                        //    this.ErrorText = "项目类型编码已存在";
                        //    res = false;
                        //}
                        //else
                        //{
                        //    res = true;
                        //}
                    }
                }
            }
            return res;
        }
    }
    /// <summary>
    ///  电话号码(可输入分机号)  可空
    /// <creator>rend</creator>
    /// <date>2012-02-25</date> 
    /// </summary>
    public class TelExtensionValidationRule : ValidationRule
    {
        public override bool Validate(Control control, object value)
        {
            bool res = true;
            if (value != DBNull.Value)
            {
                if (null != value)
                {
                    string str = ((string)value).Trim();
                    if (str != string.Empty)
                    {
                        res = GlobalUtil.CheckTelExtensionValidate(str);
                    }
                }
            }

            return res;
        }
    }


    /// <summary>
    ///  电话号码(可输入分机号)  不可空
    /// <creator>rend</creator>
    /// <date>2012-02-25</date> 
    /// </summary>
    public class TelExtensionNoEmptyValidationRule : ValidationRule
    {
        public override bool Validate(Control control, object value)
        {
            bool res = false;
            this.ErrorText = "值不能为空!";
            if (value != DBNull.Value)
            {
                if (null != value)
                {
                    string str = ((string)value).Trim();
                    if (str != string.Empty)
                    {
                        this.ErrorText = "格式不正确!";
                        res = GlobalUtil.CheckTelExtensionValidate(str);
                    }
                }
            }

            return res;
        }
    }




    /// <summary>
    ///  电话号码  可空
    /// <creator>rend</creator>
    /// <date>2012-02-25</date> 
    /// </summary>
    public class TelValidationRule : ValidationRule
    {
        public override bool Validate(Control control, object value)
        {
            bool res = true;
            if (value != DBNull.Value)
            {
                if (null != value)
                {
                    string str = ((string)value).Trim();
                    if (str != string.Empty)
                    {
                        this.ErrorText = "格式不正确!";
                        res = GlobalUtil.CheckTelValidate(str);
                    }
                }
            }

            return res;
        }
    }


    /// <summary>
    ///  电话号码  不可空
    /// <creator>rend</creator>
    /// <date>2012-02-25</date> 
    /// </summary>
    public class TelNoEmptyValidationRule : ValidationRule
    {
        public override bool Validate(Control control, object value)
        {
            bool res = false;
            this.ErrorText = "值不能为空!";
            if (value != DBNull.Value)
            {
                if (null != value)
                {
                    string str = ((string)value).Trim();
                    if (str != string.Empty)
                    {
                        res = GlobalUtil.CheckTelValidate(str);
                    }
                }
            }

            return res;
        }
    }




    /// <summary>
    /// EMail  可空
    /// <creator>rend</creator>
    /// <date>2012-02-25</date> 
    /// </summary>
    public class EMailValidationRule : ValidationRule
    {
        public override bool Validate(Control control, object value)
        {
            bool res = true;
            this.ErrorText = "邮箱格式不正确";
            if (value != DBNull.Value)
            {
                if (null != value)
                {
                    string str = ((string)value).Trim();
                    if (str != string.Empty)
                    {
                        res = GlobalUtil.CheckEMailValidate(str);
                    }
                }
            }
            return res;
        }
    }


    /// <summary>
    /// EMail  不可空
    /// <creator>rend</creator>
    /// <date>2012-02-25</date> 
    /// </summary>
    public class EMailNoEmptyValidationRule : ValidationRule
    {
        public override bool Validate(Control control, object value)
        {
            bool res = false;
            this.ErrorText = "值不能为空!";
            if (value != DBNull.Value)
            {
                if (null != value)
                {
                    string str = ((string)value).Trim();
                    if (str != string.Empty)
                    {
                        this.ErrorText = "格式不正确!";
                        res = GlobalUtil.CheckEMailValidate(str);
                    }
                }
            }
            return res;
        }
    }


    /// <summary>
    /// 手机号码验证 如果手机号码,办公号码,家庭号码都为空返回false,如果手机号码不为空则验证手机是否在号码段中(联系人功能)
    /// <creator>rend</creator>
    /// <date>2012-02-27</date> 
    /// </summary>
    //public class MobilOfficeHomeValidationRule : ValidationRule
    //{
    //    public override bool Validate(Control control, object value)
    //    {
    //        bool res = true;
    //        bool empty = true;
    //        if (value != DBNull.Value)
    //        {
    //            if (null != value)
    //            {
    //                string str = ((string)value).Trim();
    //                if (str != string.Empty)
    //                {
    //                    empty = false;
    //                    res = GlobalUtil.CheckMobilValidate(str);
    //                    if (res == true)
    //                    {
    //                        res = UtilDate.MobileNoRange(str);
    //                        this.ErrorText = "手机号码在号码段中不存在!";
    //                    }
    //                    else
    //                    {
    //                        this.ErrorText = "格式不正确,请输入11位或0开始的12位数字!";
    //                    }
    //                }
    //            }
    //        }

    //        if (empty)
    //        {
    //            Control preControl = control.Parent;
    //            if (null != preControl)
    //            {
    //                string officeTel = preControl.Controls.Find("txt_office_tel", false)[0].Text.Trim();
    //                string homeTel = preControl.Controls.Find("txt_home_tel", false)[0].Text.Trim();
    //                if (officeTel == string.Empty && homeTel == string.Empty)
    //                {
    //                    res = false;
    //                    this.ErrorText = "手机、办公电话、家庭电话必须输入一个!";
    //                }
    //            }
    //        }


    //        return res;
    //    }
    //}




    /// <summary>
    /// 操作数据库公共类
    /// </summary>
    //public class UtilDate
    //{
    //    /// <summary>
    //    /// 判断号码是否在号码段中存在
    //    /// </summary>
    //    /// <param name="mobile"></param>
    //    /// <returns></returns>
    //    public static bool MobileNoRange(string mobile)
    //    {
    //        bool bl = false;
    //        BLL.ClientEdit ClientEditBll = new BLL.ClientEdit();
    //        List<Model.MobileNoRange> mobileList = ClientEditBll.GetMobileNoRangeListAll();
    //        if (mobileList.Count == 0)
    //        {
    //            bl = true;
    //        }
    //        else
    //        {
    //            mobileList.ForEach(c =>
    //            {
    //                if (mobile.IndexOf(c.FMobileBeginNo) == 0)
    //                {
    //                    bl = true;
    //                    return;
    //                }
    //            });
    //        }
    //        return bl;
    //    }
    //}

    #endregion


    #region DockPanel Caption颜色相关

    public class MyDockElementsSkinPainter : DockElementsSkinPainter
    {
        public MyDockElementsSkinPainter(SkinBarManagerPaintStyle paintStyle) : base(paintStyle) { }
        protected override void CreateElementPainters()
        {
            base.CreateElementPainters();
            fTabPanelPainter = new MyTabPanelSkinPainter(this);
        }
    }
    public class MyTabPanelSkinPainter : TabPanelSkinPainter
    {
        public MyTabPanelSkinPainter(DockElementsSkinPainter painter) : base(painter) { }

        private DockPanel _CurrentDockPanel;
        public DockPanel CurrentDockPanel
        {
            get { return _CurrentDockPanel; }
            set { _CurrentDockPanel = value; }
        }

        protected override void DrawButtonText(DrawTabTextArgs args)
        {
            args.Appearance.Assign(CurrentDockPanel.Appearance);
            base.DrawButtonText(args);
        }
        protected override void DrawTabCore(DrawTabArgs args)
        {
            CurrentDockPanel = args.TabLayout.Panel;
            base.DrawTabCore(args);



        }
    }
    public class MyPaintStyle : SkinBarManagerPaintStyle
    {

        public MyPaintStyle(BarManagerPaintStyleCollection collection)
            : base(collection)
        {
        }
        public override string Name { get { return "MyScheme"; } }
        protected override void CreatePainters()
        {
            base.CreatePainters();
            fElementsPainter = new MyDockElementsSkinPainter(this);
        }


    }
    #endregion

}


